package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CodeImgService;
import com.atguigu.spzx.model.dto.sys.LoginDto;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.entity.sys.SysUser;
import com.atguigu.spzx.model.vo.sys.LoginVo;
import com.atguigu.spzx.manager.service.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * title:
 * author: zgl
 * date: 2023/12/26
 * description：
 */
@RestController
@RequestMapping("/admin/system/index")
@Tag(name = "index管理模块")
//@CrossOrigin(originPatterns = {"*"}, allowCredentials = "true", allowedHeaders = {"*"})
public class IndexController {
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private CodeImgService codeImgService;

    @DeleteMapping("/logout")
    @Operation(summary = "退出登录接口")
    public Result logout(@RequestHeader String token) {
        sysUserService.logout(token);
        return Result.ok();
    }
   /* @GetMapping("/userInfo")
    public Result getUserInfo(@RequestHeader String token) {
        SysUser sysUser = sysUserService.getUserInfo(token);
        return Result.ok(sysUser);
    }*/

    @GetMapping("/userInfo")
    @Operation(summary = "获取用户信息接口")
    public Result getUserInfo() {
        SysUser sysUser = sysUserService.getUserInfo();
        return Result.ok(sysUser);
    }

    @PostMapping("/login")
    @Operation(summary = "登录接口")
    public Result login(@RequestBody LoginDto loginDto) {
        LoginVo loginVo = sysUserService.login(loginDto);
        return Result.ok(loginVo);
    }

    @GetMapping("/getCode")
    @Operation(summary = "获取验证码接口")
    public Result getCodeImg() {
        Map map = codeImgService.getCodeImg();
        return Result.ok(map);
    }
}
